package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.entity.Employee;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Liu
 * @date: 2022/02/26
 * @time: 15:04
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    @PostMapping
    public R<String> add(@RequestBody Category category) {
        return categoryService.add(category);
    }

    @GetMapping("/page")
    public R<Page<Category>> page(Long page, Long pageSize) {
        return categoryService.page(page, pageSize);
    }

    @DeleteMapping
    public R<String> delete(Long id) {
        return categoryService.delete(id);
    }

    @PutMapping
    public R<String> update(@RequestBody Category category) {
        return categoryService.update(category);
    }

    @GetMapping("/list")
    public R<List<Category>> list(@RequestParam(required = false) Integer type) {
        return categoryService.list(type);
    }
}
